﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;

namespace Digitalmes.ControlEx;

/// <summary>
/// 矩形
/// </summary>
public partial class Rect : UserControl, INotifyPropertyChanged
{
    public event PropertyChangedEventHandler? PropertyChanged;

    /// <summary>
    /// 是否鼠标正处于按下状态
    /// </summary>
    public bool IsPreviewMouseDown { get; set; }

    /// <summary>
    /// 控件当前鼠标按下的位置
    /// </summary>
    public Point MouseDownPosition { get; set; }

    /// <summary>
    /// 控件当前在 Canvas 中的位置
    /// </summary>
    public Point CanvasPosition { get; set; }

    /// <summary>
    /// 原始状态
    /// </summary>
    internal RectState OriginalState { get; init; }

    public Rect()
    {
        InitializeComponent();
        DataContext = this;
    }

    private string? _text;
    /// <summary>
    /// 显示文本
    /// </summary>
    [Bindable(true), Category("属性")]
    public string? Text
    {
        get { return _text; }
        set { _text = value; OnPropertyChanged(nameof(Text)); }
    }

    private int _no;
    /// <summary>
    /// 编号
    /// </summary>
    [Bindable(true), Category("属性")]
    public int No
    {
        get { return _no; }
        set { _no = value; OnPropertyChanged(nameof(Index)); }
    }

    private string _group = string.Empty;
    /// <summary>
    /// 索引分组
    /// </summary>
    [Bindable(true), Category("属性")]
    public string Group
    {
        get { return _group; }
        set { _group = value; OnPropertyChanged(nameof(Group)); }
    }

    private RectState _state = RectState.None;
    /// <summary>
    /// 状态
    /// </summary>
    [Bindable(true), Category("属性")]
    public RectState State
    {
        get { return _state; }
        set { _state = value; OnPropertyChanged(nameof(State)); }
    }

    protected internal virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
